package h0910;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 比较版本号
 * @date 2024/9/10 17:46
 */
public class CompareVersionNum {
    public static void main(String[] args) {

    }

    public int compareVersion(String version1, String version2) {
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");
        int n = Math.max(s1.length, s2.length);
        for (int i = 0; i < n; i++) {
            int a = i < s1.length ? Integer.parseInt(s1[i]) : 0;
            int b = i < s2.length ? Integer.parseInt(s2[i]) : 0;
            if (a>b){
                return 1;
            }else if (a<b){
                return -1;
            }
        }
        return 0;
    }
}
